Skip to content

simplify algebra in Year offset apply methods #18280

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 16, 2017

Conversation

jbrockmendel
Copy link
Member

This PR is careful to only touch YearEnd and YearBegin classes, so should not overlap with #18263 or #18278. But like 18278, once the algebra is simplified, it looks an awful lot like 18263.

The bad news is that the process of simplifying the dynamically-defined _increment, _decrement, _rollf functions is no fun, and I'm not aware of any good way to "show your work" to walk through the in-between steps.

  • closes #xxxx
  • tests added / passed
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry

@codecov
Copy link

codecov bot commented Nov 14, 2017

Codecov Report

Merging #18280 into master will decrease coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #18280      +/-   ##
==========================================
- Coverage   91.39%   91.37%   -0.03%     
==========================================
  Files         164      164              
  Lines       49854    49808      -46     
==========================================
- Hits        45566    45511      -55     
- Misses       4288     4297       +9
Flag Coverage Δ
#multiple 89.17% <100%> (-0.01%) ⬇️
#single 39.47% <0%> (-0.03%) ⬇️
Impacted Files Coverage Δ
pandas/tseries/offsets.py 96.96% <100%> (-0.1%) ⬇️
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/core/frame.py 97.8% <0%> (-0.1%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9c799e2...369da47. Read the comment docs.

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question, do we have sufficient tests for this?

@@ -428,3 +428,36 @@ cpdef datetime shift_month(datetime stamp, int months, object day_opt=None):
else:
raise ValueError(day_opt)
return stamp.replace(year=year, month=month, day=day)


cpdef int _get_day_of_month(datetime other, day_opt):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

de-privatize

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add doc-string (examples too!)

Possibly increment or decrement the number of periods to shift
based on rollforward/rollbackward conventions.

Mirrors `roll_check` in tslib.shift_months
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doc-string & examples

@jreback jreback added the Frequency DateOffsets label Nov 14, 2017
@jbrockmendel
Copy link
Member Author

same question, do we have sufficient tests for this?

As in #18263, I think so, yes.

@jreback jreback added this to the 0.22.0 milestone Nov 15, 2017
@jreback jreback added the Clean label Nov 15, 2017
@jreback
Copy link
Contributor

jreback commented Nov 15, 2017

are there unit tests for these (can you point)? in particular the raising of get_day_of_month?

-6

"""
# Note: The other.day < ... condition will never hold when day_opt=='start'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

theoretically you should assert day_opt here (because if n=0 it is not checked)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean assert that it is valid? Sure.

BTW good call on testing the raising get_day_of_month. The exception gets ignored without an except -1.

@jbrockmendel
Copy link
Member Author

are there unit tests for these (can you point)? in particular the raising of get_day_of_month?

There aren't any specific tests for these. I'll add some.

@jreback
Copy link
Contributor

jreback commented Nov 15, 2017

yeah i suspect lots of things are not unit tested so taking this opportunity to put in place :)

@jbrockmendel
Copy link
Member Author

Sounds good. Another BTW: we can get coverage for _libs: #12634 (comment)

@jreback jreback merged commit 1e83d87 into pandas-dev:master Nov 16, 2017
@jreback
Copy link
Contributor

jreback commented Nov 16, 2017

thanks! I love unit tests & doc-strings!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants